package crp.core.security.app;

import crp.core.security.domain.services.BasicAuthenticator;
import crp.core.security.domain.services.PermissionChecker;
import crp.core.security.domain.services.PermissionLoader;
import crp.core.security.domain.services.SSOAuthenticator;
import crp.core.security.domain.services.UserAuthorizer;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;

@ApplicationScoped
public class AuthService {
    private final Instance<BasicAuthenticator> basicAuthenticator;
    private final Instance<SSOAuthenticator> ssoAuthenticator;
    private final Instance<PermissionChecker> permissionChecker;
    private final Instance<PermissionLoader> permissionLoader;
    private final Instance<UserAuthorizer> authorizers;

    @Inject
    public AuthService(Instance<BasicAuthenticator> basicAuthenticator,
                       Instance<SSOAuthenticator> ssoAuthenticator,
                       Instance<PermissionChecker> permissionChecker,
                       Instance<PermissionLoader> permissionLoader,
                       Instance<UserAuthorizer> authorizers) {
        this.basicAuthenticator = basicAuthenticator;
        this.ssoAuthenticator = ssoAuthenticator;
        this.permissionChecker = permissionChecker;
        this.permissionLoader = permissionLoader;
        this.authorizers = authorizers;
    }

    public BasicAuthenticator basic() {
        return basicAuthenticator.get();
    }

    public SSOAuthenticator sso() {
        return ssoAuthenticator.get();
    }

    public PermissionChecker check() {
        return permissionChecker.get();
    }

    public PermissionLoader permissionLoader() {
        return permissionLoader.get();
    }

    public UserAuthorizer authorizer() {
        return authorizers.get();
    }
}
